package com.kungfuhacking.wristbandpro.chat.presenter;

import android.content.Context;
import android.net.Uri;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.kungfuhacking.wristbandpro.R;
import com.kungfuhacking.wristbandpro.chat.bean.UserListBean;

import java.util.List;

/**
 * 群设置 成员adapter
 * Created by Aaron on 16/2/23.
 */
public class GroupSettingNumAdapter extends BaseAdapter {

    private Context ctx;
    private List<UserListBean.UserListEntity> userList;
//    private boolean isAdmin;
//    private boolean childGroup;

    //    public GroupSettingNumAdapter(Context ctx, List<GroupSettingBean.TopicEntity.UserListEntity> userList, boolean isAdmin, boolean childGroup) {
    public GroupSettingNumAdapter(Context ctx, List<UserListBean.UserListEntity> userList) {
        this.ctx = ctx;
        this.userList = userList;
//        this.isAdmin = isAdmin;
//        this.childGroup = childGroup;
    }

//    public void setAdmin(boolean admin) {
//        isAdmin = admin;
//    }

//    public void setChildGroup(boolean childGroup) {
//        this.childGroup = childGroup;
//    }

    @Override
    public int getCount() {

//        if (childGroup)
        return userList.size();

//        if (isAdmin)
//            return userList.size() + 2;//如果是群主,则多2个
//
//        return userList.size() + 1;
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int i, View convertView, ViewGroup viewGroup) {

        ViewHolder viewHolder = null;

        if (convertView == null) {

            convertView = View.inflate(ctx, R.layout.item_group_num, null);
            viewHolder = new ViewHolder();

            viewHolder.iv_head_pic = (SimpleDraweeView) convertView.findViewById(R.id.iv_head_pic);
            viewHolder.tv_nickname = (TextView) convertView.findViewById(R.id.tv_nickname);

            convertView.setTag(viewHolder);

        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

//        if (i == userList.size() + 1) {
//            //删除群成员的图片
//            viewHolder.iv_head_pic.setImageResource(R.mipmap.ic_subtract);
//            viewHolder.tv_nickname.setText("");
//            return convertView;
//        }
//
//        if (i == userList.size()) {
//            //添加群成员的图片
//            viewHolder.iv_head_pic.setImageResource(R.mipmap.ic_plus);
//            viewHolder.tv_nickname.setText("");
//            return convertView;
//        }

//        if (userList == null || userList.get(i) == null || userList.get(i).user == null)
//            return convertView;

        //设置昵称
        viewHolder.tv_nickname.setText(userList.get(i).getNickName());

        //设置头像
        viewHolder.iv_head_pic.setImageURI(Uri.parse(
                TextUtils.isEmpty(userList.get(i).getImgUrl()) ? "" : userList.get(i).getImgUrl()));

        return convertView;
    }

    private class ViewHolder {

        private SimpleDraweeView iv_head_pic;
        private TextView tv_nickname;

    }

}